﻿using PlutoStudio.Net.Messages;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PlutoStudio.Net.Processors
{
    public abstract class ActionResult
    {
        internal protected abstract void ExecuteResult(MessageProcessorBase process, IEncryptionFilter encryption);
    }


    public class JsonResult : ActionResult
    {
        public object Data { get; set; }


        protected internal override void ExecuteResult(MessageProcessorBase process, IEncryptionFilter encryption)
        {
            var message = new Message(process.Message.Flag, process.Message.Code, (ushort)process.StatusCode);
            message.MessageId = process.Message.MessageId;
            if (Data != null)
            {
                message.SetData(Data);
            }
            if (encryption != null)
            {
                message = encryption.OnEncryptValue(process, message);
            }
            process.Context.Send(message);

        }

        public JsonResult(object data)
        {
            this.Data = data;
        }
    }

    public class ContentResult : ActionResult
    {
        public string Content { get; set; }

        protected internal override void ExecuteResult(MessageProcessorBase process, IEncryptionFilter encryption)
        {
            var message = new Message(process.Message.Flag, process.Message.Code, (ushort)process.StatusCode);
            message.MessageId = process.Message.MessageId;
            if (Content != null)
            {
                message.SetData(Content);
            }
            if (encryption != null)
            {
                message = encryption.OnEncryptValue(process, message);
            }
            process.Context.Send(message);
        }

        public ContentResult(string content)
        {
            this.Content = content;
        }
    }

    public class EmptyResult : ActionResult
    {
        protected internal override void ExecuteResult(MessageProcessorBase process, IEncryptionFilter encryption)
        {
            var message = new Message(process.Message.Flag, process.Message.Code, (ushort)process.StatusCode);
            message.MessageId = process.Message.MessageId;
            process.Context.Send(message);
        }
    }


}
